﻿<template>
    <div class="big_box">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>人员管理</el-breadcrumb-item>
            <el-breadcrumb-item>职位列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-divider></el-divider>

        <el-form class="demo-form-inline" label-width="0px" :model="AddPosiTionMain" ref="TionMainref" :rules="rules">
            <el-row :gutter="5">
                <el-col :span="3">
                    <el-input v-model="SelName" placeholder="请输入职位名称"></el-input>
                </el-col>
                <el-col :span="2"  >
                    <el-button   icon="el-icon-search"  style="width:100%"  @click="GettableDB()"> </el-button>
                </el-col>
            </el-row>

            <el-row :gutter="5" style="padding-top:10px">
                <el-col :span="3">
                    <el-form-item prop="DutyName">
                        <el-input v-model="AddPosiTionMain.DutyName" placeholder="请输入职位名称"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="3">
                    <el-form-item prop="Level">
                        <el-select v-model="AddPosiTionMain.Level" class="wmax" required placeholder="请选择级别">
                            <el-option :value="1" label="一级">一级</el-option>
                            <el-option :value="2" label="二级">二级</el-option>
                            <el-option :value="3" label="三级">三级</el-option>
                            <el-option :value="4" label="四级">四级</el-option>
                            <el-option :value="5" label="五级">五级</el-option>
                            <el-option :value="6" label="六级">六级</el-option>
                            <el-option :value="7" label="七级">七级</el-option>
                            <el-option :value="8" label="八级">八级</el-option>
                            <el-option :value="9" label="九级">九级</el-option>
                            <el-option :value="10" label="十级">十级</el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="3">
                    <el-form-item prop="Remarks">
                        <el-input v-model="AddPosiTionMain.Remarks" placeholder="请输入备注信息"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="2" style="padding-left:10px">
                    <el-button icon="el-icon-circle-plus-outline" @click="AddformSubmit_Posi()">添加新职位</el-button>
                </el-col>
            </el-row>
        </el-form>
        <el-row style="padding-top: 10px">
            <el-col>
                <el-table :data="tableData"
                          style="width: 100%"
                          border>
                    <el-table-column header-align="center" fixed type="index" label="序号" width="50" align="center" :index="_indexMethod"></el-table-column>
                    <el-table-column header-align="center" fixed prop="DutyName" label="职位名称" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column header-align="center" fixed prop="Level" label="级别" align="center">   </el-table-column>
                    <el-table-column header-align="center" prop="Remarks" label="备注" align="center"> </el-table-column>
                    <el-table-column header-align="center" prop="UserPosition" label="编辑" align="center" maxWidth='200'>
                        <template slot-scope="scope">
                            <el-button type="primary" class="BtnSize" size="mini" plain @click="edit(scope.row)">编辑</el-button>
                            <el-button type="danger" class="BtnSize" size="mini" plain @click="dele(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>


        <el-dialog :visible.sync="UpPosiTionMainShow" title="修改职务信息" width="40%">
            <el-form class="demo-form-inline" label-width="140px">
                <el-row>
                    <el-col :span="20" :offset="1">
                        <el-form-item label="职位名称">
                            <el-input v-model="UpPosiTionMain.DutyName"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20" :offset="1">
                        <el-form-item label="级别" prop="RoleId">
                            <el-select v-model="UpPosiTionMain.Level" class="wmax" required placeholder="请选择级别" style="width:100%">
                                <el-option :value="1" label="一级">一级</el-option>
                                <el-option :value="2" label="二级">二级</el-option>
                                <el-option :value="3" label="三级">三级</el-option>
                                <el-option :value="4" label="四级">四级</el-option>
                                <el-option :value="5" label="五级">五级</el-option>
                                <el-option :value="6" label="六级">六级</el-option>
                                <el-option :value="7" label="七级">七级</el-option>
                                <el-option :value="8" label="八级">八级</el-option>
                                <el-option :value="9" label="九级">九级</el-option>
                                <el-option :value="10" label="十级">十级</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20" :offset="1">
                        <el-form-item label="备注" prop="Remarks">
                            <el-input v-model="UpPosiTionMain.Remarks"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row style="text-align:center">
                    <el-button icon="el-icon-Add" @click="UpformSubmit_Posi()">修改职位信息</el-button>
                </el-row>
            </el-form>
        </el-dialog>

    </div>

</template>

<script>
    export default {
        name: "PosiTionMain",
        data() {
            return {
                SelName: "",
                UpPosiTionMainShow: false,
                AddPosiTionMain: {
                },
                //表格数据信息
                tableData: [],
                //修改组织信息
                UpPosiTionMain: {},
                //分页数据绑定
                pagination: {
                    currentPage: 1,
                    pagesizes: [15, 50, 100,],
                    pagesize: 15,
                    total: 0
                },
                rules: {
                    DutyName: [
                        { required: true, message: '请输入职位名称', trigger: 'blur' },
                    ],
                    Level: [
                        { required: true, message: '请选择级别', trigger: 'change' }
                    ]
                },
            };
        },
        created() {
            //this.AllUsers = publicjs.GetCompanyAllUsers(this.$http);
            //this.AllDepartment = publicjs.GetAllDepartment(this.$http);
            this.GettableDB();
        },
        methods: {
            _indexMethod(index) {
                return ((this.pagination.currentPage - 1) * this.pagination.pagesize) + index + 1
            },
            GettableDB() {
                this.$http.post("/Department/PosiTionMain", { name: this.SelName }).then(x => {
                    this.tableData = x.data.data;
                })
            },
            edit(obj) {
                this.UpPosiTionMainShow = true;
                this.UpPosiTionMain = JSON.parse(JSON.stringify(obj));
            },
            dele(obj) {
                console.log(obj);
                this.$confirm('你确定要删除吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'error'
                }).then(() => {
                    let loadding = this.openLoading();
                    this.$http.post("/Department/DletePosiTion", { id: obj.Id }).then(x => {
                        loadding.close();
                        if (x.data.bit) {
                            this.$message.success("信息删除成功");
                            this.GettableDB();
                        } else {
                            this.$message.success("信息删除失败");
                        }
                    })
                });
            },

            AddformSubmit_Posi() {
                let _this = this
                this.$refs["TionMainref"].validate(x => {
                    if (x) {
                        let loadding = this.openLoading();
                        this.$http.post("/Department/AddPosiTion", { AddPosiTionMain: this.AddPosiTionMain }).then(x => {
                            loadding.close();
                            if (x.data.message.IsSuccess) {
                                _this.$message.success(x.data.message.Msg);
                                _this.UpPosiTionMainShow = false;
                                _this.GettableDB();
                                _this.$refs["TionMainref"].resetFields()
                            } else {
                                _this.$message.warning(x.data.message.Msg);
                            }
                        })
                    }
                })
            },


            UpformSubmit_Posi() {
                let loadding = this.openLoading();
                this.$http.post("/Department/UpdateDuty", { UpPosiTionMain: this.UpPosiTionMain }).then(x => {
                    loadding.close();
                    if (x.data.bit) {
                        this.$message.success("信息修改成功");
                        this.UpPosiTionMainShow = false;
                        this.GettableDB();
                    } else {
                        this.$message.success("信息修改失败");
                    }
                })
            },

        },



    }
</script>

<style scoped>
    el-col {
    padding-left:10px;
    }
</style>
